#include <stdio.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrCoreGeometry.h>
#include "../macro.h"

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstSet_Data2d_Vector(dtype)					\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 1};			\
									\
  FLGR_Data2D *img, *imgref;						\
  FLGR_Vector *vec;							\
  FLGR_Ret ret;								\
  dtype val=1;								\
									\
  imgref    = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
  img       = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
									\
  vec = flgr_vector_create(img->spp,img->type);				\
  flgr_vector_populate_from_scalar(vec,&val);				\
									\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  flgr2d_clear_all(img);						\
  									\
									\
  ret = flgr2d_set_data_vector(img,7,9,vec);				\
  check_and_display_data2d(imgref,img,ret);				\
									\
									\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr_vector_destroy(vec);						\
									\
  return 1

int testset_data2d_vector_fgBIT(void) {
  tstSet_Data2d_Vector(fgBIT);
}
int testset_data2d_vector_fgUINT8(void) {
  tstSet_Data2d_Vector(fgUINT8);
}
int testset_data2d_vector_fgUINT16(void) {
  tstSet_Data2d_Vector(fgUINT16);
}
int testset_data2d_vector_fgUINT32(void) {
  tstSet_Data2d_Vector(fgUINT32);
}
int testset_data2d_vector_fgINT8(void) {
  tstSet_Data2d_Vector(fgINT8);
}
int testset_data2d_vector_fgINT16(void) {
  tstSet_Data2d_Vector(fgINT16);
}
int testset_data2d_vector_fgINT32(void) {
  tstSet_Data2d_Vector(fgINT32);
}
int testset_data2d_vector_fgFLOAT32(void) {
  tstSet_Data2d_Vector(fgFLOAT32);
}
int testset_data2d_vector_fgFLOAT64(void) {
  tstSet_Data2d_Vector(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstGet_Data2d_Vector(dtype)					\
									\
  dtype rawref[]={1, 1, 1, 1, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 0, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,				\
		  1, 1, 1, 1, 1, 1, 1, 1, 1, 1};			\
  									\
  FLGR_Data2D *img,*imgref;						\
  FLGR_Vector *vec;							\
  FLGR_Ret ret;								\
									\
  imgref   = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
  img      = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX); \
									\
  vec = flgr_vector_create(img->spp,img->type);				\
									\
  flgr2d_import_raw_ptr(imgref,rawref);					\
  flgr2d_draw_filled_rectangle_str(img,0,0,10,8,"1");			\
									\
  ret = flgr2d_get_data_vector(imgref,3,8,vec);				\
  flgr2d_set_data_vector(img,3,8,vec);					\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
									\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr_vector_destroy(vec);						\
									\
									\
  return 1

int testget_data2d_vector_fgBIT(void) {
  tstGet_Data2d_Vector(fgBIT);
}
int testget_data2d_vector_fgUINT8(void) {
  tstGet_Data2d_Vector(fgUINT8);
}
int testget_data2d_vector_fgUINT16(void) {
  tstGet_Data2d_Vector(fgUINT16);
}
int testget_data2d_vector_fgUINT32(void) {
  tstGet_Data2d_Vector(fgUINT32);
}
int testget_data2d_vector_fgINT8(void) {
  tstGet_Data2d_Vector(fgINT8);
}
int testget_data2d_vector_fgINT16(void) {
  tstGet_Data2d_Vector(fgINT16);
}
int testget_data2d_vector_fgINT32(void) {
  tstGet_Data2d_Vector(fgINT32);
}
int testget_data2d_vector_fgFLOAT32(void) {
  tstGet_Data2d_Vector(fgFLOAT32);
}
int testget_data2d_vector_fgFLOAT64(void) {
  tstGet_Data2d_Vector(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstClear2d_All(dtype)						\
									\
  dtype raw[]={33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33,			\
	       33, 33, 33, 33, 33, 33, 33, 33, 33, 33};			\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};			\
									\
  FLGR_Data2D *img, *imgref;						\
  FLGR_Ret ret;								\
									\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(img,raw);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret = flgr2d_clear_all(img);						\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

int testclear2d_all_fgBIT(void) {
  tstClear2d_All(fgBIT);
}
int testclear2d_all_fgUINT8(void) {
  tstClear2d_All(fgUINT8);
}
int testclear2d_all_fgUINT16(void) {
  tstClear2d_All(fgUINT16);
}
int testclear2d_all_fgUINT32(void) {
  tstClear2d_All(fgUINT32);
}
int testclear2d_all_fgINT8(void) {
  tstClear2d_All(fgINT8);
}
int testclear2d_all_fgINT16(void) {
  tstClear2d_All(fgINT16);
}
int testclear2d_all_fgINT32(void) {
  tstClear2d_All(fgINT32);
}
int testclear2d_all_fgFLOAT32(void) {
  tstClear2d_All(fgFLOAT32);
}
int testclear2d_all_fgFLOAT64(void) {
  tstClear2d_All(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstExport2d_Data_Ptr(dtype)					\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0,18,19, 0, 0,				\
		  0, 0, 0,12, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0,15, 0, 0, 0, 0,				\
		  0, 0, 0, 0,13, 0, 0, 0, 0, 0,				\
		  0,14, 0, 0, 0, 0,16, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 1};			\
									\
  FLGR_Data2D *img, *imgref;						\
  FLGR_Ret ret;								\
  dtype val[80];							\
									\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret = flgr2d_export_raw_ptr(val,imgref);				\
  flgr2d_import_raw_ptr(img,val);					\
  check_and_display_data2d(imgref,img,ret);				\
									\
									\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

int testexport2d_data_ptr_fgBIT(void) {
  tstExport2d_Data_Ptr(fgBIT);
}
int testexport2d_data_ptr_fgUINT8(void) {
  tstExport2d_Data_Ptr(fgUINT8);
}
int testexport2d_data_ptr_fgUINT16(void) {
  tstExport2d_Data_Ptr(fgUINT16);
}
int testexport2d_data_ptr_fgUINT32(void) {
  tstExport2d_Data_Ptr(fgUINT32);
}
int testexport2d_data_ptr_fgINT8(void) {
  tstExport2d_Data_Ptr(fgINT8);
}
int testexport2d_data_ptr_fgINT16(void) {
  tstExport2d_Data_Ptr(fgINT16);
}
int testexport2d_data_ptr_fgINT32(void) {
  tstExport2d_Data_Ptr(fgINT32);
}
int testexport2d_data_ptr_fgFLOAT32(void) {
  tstExport2d_Data_Ptr(fgFLOAT32);
}
int testexport2d_data_ptr_fgFLOAT64(void) {
  tstExport2d_Data_Ptr(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstImport2d_Data_Ptr(dtype)					\
									\
  dtype rawref[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0,18,19, 0, 0,				\
		  0, 0, 0,12, 0, 0, 0, 0, 0, 0,				\
		  0, 0, 0, 0, 0,15, 0, 0, 0, 0,				\
		  0, 0, 0, 0,13, 0, 0, 0, 0, 0,				\
		  0,14, 0, 0, 0, 0,16, 0, 0, 0,				\
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 1};			\
									\
  FLGR_Data2D *img, *imgref;						\
  FLGR_Ret ret;								\
  dtype val[80];							\
									\
  imgref  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  flgr2d_export_raw_ptr(val,imgref);					\
  ret = flgr2d_import_raw_ptr(img,val);					\
  check_and_display_data2d(imgref,img,ret);				\
									\
									\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

int testimport2d_data_ptr_fgBIT(void) {
  tstImport2d_Data_Ptr(fgBIT);
}
int testimport2d_data_ptr_fgUINT8(void) {
  tstImport2d_Data_Ptr(fgUINT8);
}
int testimport2d_data_ptr_fgUINT16(void) {
  tstImport2d_Data_Ptr(fgUINT16);
}
int testimport2d_data_ptr_fgUINT32(void) {
  tstImport2d_Data_Ptr(fgUINT32);
}
int testimport2d_data_ptr_fgINT8(void) {
  tstImport2d_Data_Ptr(fgINT8);
}
int testimport2d_data_ptr_fgINT16(void) {
  tstImport2d_Data_Ptr(fgINT16);
}
int testimport2d_data_ptr_fgINT32(void) {
  tstImport2d_Data_Ptr(fgINT32);
}
int testimport2d_data_ptr_fgFLOAT32(void) {
  tstImport2d_Data_Ptr(fgFLOAT32);
}
int testimport2d_data_ptr_fgFLOAT64(void) {
  tstImport2d_Data_Ptr(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstImport2d_spp2_Data_Ptr(dtype)				\
									\
  dtype rawref[]={0,0,  0,0, 0,0,  0,0,  0,0, 0,0, 0,0, 0,0, 0,0, 0,0,	\
		  0,0,  0,0, 0,0,  0,0,  0,0, 0,0, 0,0, 0,0, 0,0, 0,0,	\
		  0,0,  0,0, 0,0,  0,0, 0,0, 0,0,18,18,19,19, 0,0, 0,0, \
		  0,0,  0,0, 0,0,12,12,  0,0, 0,0, 0,0, 0,0, 0,0, 0,0,	\
		  0,0,  0,0, 0,0,  0,0,  0,0,15,15, 0,0, 0,0, 0,0, 0,0,	\
		  0,0,  0,0, 0,0,  0,0,13,13, 0,0, 0,0, 0,0, 0,0, 0,0,	\
		  0,0,14,14, 0,0,  0,0,  0,0, 0,0,16,16, 0,0, 0,0, 0,0,	\
		  0,0,  0,0, 0,0,  0,0,  0,0, 0,0, 0,0, 0,0, 0,0, 1,1};	\
									\
  FLGR_Data2D *img, *imgref;						\
  FLGR_Ret ret;								\
  dtype val[8*10*2];							\
									\
  imgref  = flgr2d_create_##dtype(8,10,2,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img     = flgr2d_create_##dtype(8,10,2,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  flgr2d_export_raw_ptr(val,imgref);					\
  ret = flgr2d_import_raw_ptr(img,val);					\
  check_and_display_data2d(imgref,img,ret);				\
									\
									\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

int testimport2d_spp2_data_ptr_fgBIT(void) {
  tstImport2d_spp2_Data_Ptr(fgBIT);
}
int testimport2d_spp2_data_ptr_fgUINT8(void) {
  tstImport2d_spp2_Data_Ptr(fgUINT8);
}
int testimport2d_spp2_data_ptr_fgUINT16(void) {
  tstImport2d_spp2_Data_Ptr(fgUINT16);
}
int testimport2d_spp2_data_ptr_fgUINT32(void) {
  tstImport2d_spp2_Data_Ptr(fgUINT32);
}
int testimport2d_spp2_data_ptr_fgINT8(void) {
  tstImport2d_spp2_Data_Ptr(fgINT8);
}
int testimport2d_spp2_data_ptr_fgINT16(void) {
  tstImport2d_spp2_Data_Ptr(fgINT16);
}
int testimport2d_spp2_data_ptr_fgINT32(void) {
  tstImport2d_spp2_Data_Ptr(fgINT32);
}
int testimport2d_spp2_data_ptr_fgFLOAT32(void) {
  tstImport2d_spp2_Data_Ptr(fgFLOAT32);
}
int testimport2d_spp2_data_ptr_fgFLOAT64(void) {
  tstImport2d_spp2_Data_Ptr(fgFLOAT64);
}
